﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ControllerGymTauro;

namespace ViewGymTauro
{
    public partial class IniciaSesion : Form
    {
        public static ManagerGymTauro gymMan= new ManagerGymTauro();

        public IniciaSesion()
        {
            InitializeComponent();
        }

       

        private void buttonIngresar_Click_1(object sender, EventArgs e)
        {
            this.label2.Text = "";
            buttonIngresar.Cursor = System.Windows.Forms.Cursors.AppStarting;
            if (txtDni.Text == "" || txtPassword.Text == "")
            {
                this.label2.Text = "El usuario y/o la contraseña que has introducido no son correctas";
                
            }
            else
            {
                int dni;
                if (Int32.TryParse(txtDni.Text, out dni))
                {

                    if (gymMan.validoPassWord(dni, txtPassword.Text))
                    {
                        String tipo = gymMan.getTipoByUser(Int32.Parse(txtDni.Text));
                        String name = gymMan.getNameByUser(Int32.Parse(txtDni.Text));
                        Menu menu = new Menu(tipo, name,dni);
                        menu.Visible = true;
                        this.Visible = false;
                    }
                    else
                    {
                        this.label2.Text = "El usuario y/o la contraseña que has introducido no son correctas";
                    }
                }
                else
                {
                    this.label2.Text = "El usuario y/o la contraseña que has introducido no son correctas";

                }

            }
        }

        private void txtDni_Click(object sender, EventArgs e)
        {
            this.txtDni.Text = "";
            this.label2.Text = "";
        }

        private void txtPassword_Click(object sender, EventArgs e)
        {
            this.txtPassword.Text = "";
            this.txtPassword.PasswordChar = '•';
        }

        


    }
}
